package com.codeshogun.android.swipesample;

import android.content.Context;
import android.util.AttributeSet;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ViewFlipper;

public class ActivityViewFlipper extends ViewFlipper {
	private boolean flipped;
	private Animation slideLeftIn;
	private Animation slideLeftOut;
	private Animation slideRightIn;
    private Animation slideRightOut;

	public ActivityViewFlipper(Context context, AttributeSet attrs) {
		super(context, attrs);
		slideLeftIn = AnimationUtils.loadAnimation(context, R.anim.slide_left_in);
        slideLeftOut = AnimationUtils.loadAnimation(context, R.anim.slide_left_out);
        slideRightIn = AnimationUtils.loadAnimation(context, R.anim.slide_right_in);
        slideRightOut = AnimationUtils.loadAnimation(context, R.anim.slide_right_out);
	}
	
	@Override
	public void showPrevious() {
		if (this.flipped) return;
		setInAnimation(slideRightIn);
        setOutAnimation(slideRightOut);
		this.flipped = !this.flipped;
		super.showPrevious();
	}
	
	@Override
	public void showNext() {
		if (this.flipped) return;
		setInAnimation(slideLeftIn);
        setOutAnimation(slideLeftOut);
		this.flipped = !this.flipped;
		super.showNext();
	}
	
	public boolean isFlipped() {
		return flipped;
	}
	
	public void reset() {
		if (!flipped) return;
		super.showNext();
		this.flipped = false;
	}

}
